package com.cndcare.msc.components;

import com.cndcare.msc.bean.ChannelDTO;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 工具类把客户端id作为key放入map中 把通道放入对应value，相当于做一个绑定
 */

@Component(value = "channelRepository")
public class ChannelRepository {
    public final static Map<String, ChannelDTO> channelCache = new ConcurrentHashMap<String, ChannelDTO>();

    public void put(String key, ChannelDTO channelDTO) {
        channelCache.put(key, channelDTO);
    }

    public ChannelDTO get(String key) {
        return channelCache.get(key);
    }

    public void remove(String key) {
        channelCache.remove(key);
    }

    public int size() {
        return channelCache.size();
    }
}
